Skip to content

feat(maven-plugin): add posthog-maven-plugin to upload jvm sources with hog - #1011

Open
ablaszkiewicz wants to merge 15 commits into
mainfrom
ab/feat/maven-plugin-upload-sources
Open

ablaszkiewicz wants to merge 15 commits into
mainfrom
ab/feat/maven-plugin-upload-sources

Conversation

@ablaszkiewicz

@ablaszkiewicz ablaszkiewicz commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Source code for JVM server exceptions, in release order:

  1. feat(error-tracking): show source code for jvm frames posthog#142847 cymbal: read JVM source bundles (merged)
  2. feat(cli): bundle and upload jvm sources with hog posthog#144749 hog: hog error-tracking process --kind jvm (merged)
  3. feat(server): read the map id and release id from posthog-meta.properties #1019 posthog-server: send the IDs from posthog-meta.properties
  4. feat(maven-plugin): add posthog-maven-plugin to upload jvm sources with hog #1011 Maven plugin: upload the sources at build time 👈 this PR
  5. feat(gradle-plugin): add com.posthog.jvm to upload jvm sources with hog #1012 Gradle plugin com.posthog.jvm: upload the sources at build time

What each step waits for:

💡 Motivation and Context

Maven teams need a build step that uploads their sources and packages the upload's id, so error tracking shows code on the frames of exceptions posthog-server captures. This adds com.posthog:posthog-maven-plugin with one goal, upload-sources.

  • It runs hog error-tracking process --kind jvm (feat(cli): bundle and upload jvm sources with hog posthog#144749) in process-classes, after compilation, and writes posthog-meta.properties into the classes directory. feat(server): read the map id and release id from posthog-meta.properties #1019 makes the SDK read it.
  • Running after compilation uploads the sources that annotation processors generate, such as MapStruct mappers.
  • It uploads the compile source roots, plus the <sourceDirs> of kotlin-maven-plugin, which mixed Java and Kotlin projects use. additionalSourceRoots adds other modules' directories, and sourceRoots replaces the defaults. Java sources in a non-UTF-8 encoding, also the platform default when none is set, are uploaded as UTF-8 copies. A file that is valid UTF-8 already stays as it is, so another module's UTF-8 sources keep their characters.
  • It finds hog in the same places as the Android Gradle plugin, or at posthog.hogExecutable. On Windows it runs the npm package's hog.exe instead of the .cmd shim, so arguments never pass through cmd. A shim without that binary counts as no install, and a configured .cmd path refuses values with cmd operators.
  • The release is the artifact id at the current git commit. releaseVersion overrides it.
  • Only a CI build uploads by default, so mvn test and mvn install on a laptop never upload work in progress or need the network. Offline builds skip too.
  • A module skips when another module of the build that also runs the goal depends on it, because its posthog-meta.properties could replace the application's on the classpath. An integration-test or distribution module that depends on the app does not make the app skip.
  • It runs hog --version first and needs hog 1.1.0 or newer. An older hog gets "run hog upgrade". A posthog-cli install never runs the upload, and its warning gives the hog install commands.
  • A missing or outdated hog, missing credentials (hog exits 3) or a failed upload, such as a PostHog outage, only warns, so PostHog never breaks a build.
  • requireUpload uploads from every build, also a Dockerfile outside CI, and turns each of those problems into a failure.
  • It deletes the file a previous build left, so a skipped build never ships a stale id.
  • New module wired into settings.gradle.kts, the release workflow, the Makefile and the pnpm workspace. The first release is 0.1.0.

💚 How did you test it?

  • Unit tests run the goal against a fake hog. They cover CI and offline gating, reactor libraries (also an app that an integration-test module depends on), the version check (posthog-cli, too old, new enough, a warning before the version), exit 2 and exit 3, the hog search order on Unix and Windows, cmd quoting, argument wiring, Kotlin source dirs, non-UTF-8 sources next to UTF-8 ones, a failed UTF-8 copy, and the Windows npm layout.
  • A test reads META-INF/maven/plugin.xml from the built jar and checks the goal, phase, properties and dependencies Maven reads.
  • End to end with hog built from source at feat(cli): bundle and upload jvm sources with hog posthog#144749, against a local PostHog. Every in-app frame resolved with its code line:
    • The java-maven example, as a shaded jar.
    • A build with a library, an app and an integration-test module, in CI, with ISO-8859-1 sources. The app uploads, the library skips, the library's frames resolve through additionalSourceRoots, and the umlauts show correctly. Before the fix in this PR, the app skipped too.
    • A kotlin-maven-plugin project with <sourceDirs> and mixed Java and Kotlin.
    • A local build deletes the old file. CI without credentials warns, and requireUpload without credentials fails the build.
  • Not tested: Windows (unit tests only), JDK 8 and Maven before 3.9.
Earlier runs with posthog-cli, before the move to hog
  • Maven 3.9.9 with MapStruct on a Spring Boot 3.5 project: clean and incremental builds pass target/generated-sources/annotations, and the fat jar carries the id.
  • A shaded jar, a Spring Boot 3.5 fat jar, three kotlin-maven-plugin setups, and a multi-stage Docker build against a local PostHog.
  • No credentials, no CLI, the npm posthog-cli 0.18.10 (too old), requireUpload, and a 113 MB bundle.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

The changeset .changeset/maven-plugin-upload-sources.md (minor) was written by hand in the same format.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Written with Claude Code (Claude Opus 5.5): https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
  • Pure Java and built with Gradle, so it reuses this repo's release flow.
  • Moved from posthog-cli to hog in a later Claude Code session, because posthog-cli is frozen. An older hog fails with a usage error (exit 2), which the goal turns into a warning that says to run hog upgrade.
  • The person who directed the work chose the design and the commit as default version, and asked for the CI-only and fail-open changes after a review. They have not reviewed the diff yet.
  • A self-review in a later session found that an app module skipped its upload in CI when an integration-test module depended on it, and that the UTF-8 copies garbled sources that were UTF-8 already. Both are fixed, with tests that fail on the old code.
  • Release after hog 1.1.0 is published. hog on master is 1.0.2, and its pending minor changeset makes the next release 1.1.0, which Hog.MIN_HOG_VERSION already requires.

The upload-sources goal runs posthog-cli jvm upload on the project's
sources and the source directories of kotlin-maven-plugin, and packages
the id they were uploaded under in posthog-meta.properties, which
posthog-server reads. The release version defaults to the git commit.
When posthog-cli is missing or too old, or no credentials are set, the
goal skips with a warning unless requireUpload is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
@ablaszkiewicz

Copy link
Copy Markdown
Contributor Author

@PostHog review --deep

@posthog

posthog Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@ablaszkiewicz PostHog Review is reviewing this pull request.

@posthog

posthog Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

PostHog Review · Deep · reviewed cc812b2

Posted 4 findings: 2 Should fix, 2 Consider.

Step Status Result
Prepare the diff done 14 files, 2 chunks
Pick perspectives done 3 perspectives
Run review passes done 7 issues (+2 blind-spot)
Merge overlapping findings done 9 → 9
Validate findings done 4 kept, 5 dismissed
Publish done 4 posted (view review)

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this review and its findings in PostHog Review.

ablaszkiewicz and others added 2 commits November 26, 2026 18:55
- Run upload-sources in process-classes, after compilation, so the
  sources that annotation processors generate are uploaded. The id goes
  straight into the classes directory, because process-resources has
  already run.
- Upload UTF-8 copies of Java sources whose declared encoding is not
  UTF-8. posthog-cli reads every file as UTF-8 and skips the others.
- Put the CLI's directory and node's directory on the child PATH, so an
  npm launcher found outside PATH can start node.
- On Windows, run the native binary of the npm package instead of its
  .cmd shim, so no argument passes through cmd. When only the shim can
  run, refuse values that hold cmd operators.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
Parentheses start no command in cmd, and versions such as 1.0(5) hold
them. Refuse the same characters as the Gradle plugin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review November 27, 2026 10:58
@ablaszkiewicz
ablaszkiewicz requested a review from a team as a code owner November 27, 2026 10:58
@veria-ai

veria-ai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

PR overview

Adds a PostHog Maven plugin to upload JVM sources with hog, including UTF-8 staging for sources using other encodings.

One issue has been addressed, and one remains open in source staging. When staging is enabled for non-UTF-8 sources, Java or Kotlin symlinks can cause unrelated local files to be copied into the upload, potentially exposing credentials or other files outside the source tree. Exploitation requires a source symlink and a build configured to use staging.

Open issues (1)

Fixed/addressed: 1 · PR risk: 6/10

Reviews

ablaszkiewicz and others added 2 commits November 27, 2026 14:28
Without the native binary, the plugin ran the bare name through cmd, and
cmd looks in the project directory before PATH. The plugin now treats the
shim as no install, so the build skips or fails with the install hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJA9vNowLRRGH1hbFyhv
posthog-cli now uploads the sources without a release, so unchanged
sources in a new release reuse the existing upload, and writes the
release id into posthog-meta.properties for posthog-server to send with
each exception. The README, the goal's javadoc and the changeset now say
so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJADQzM8ma8T9RauvMg5

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean pure-Java, zero-runtime-dependency Maven plugin design; we verified locally with Apache Maven 3.9.11 (JDK 17.0.16) that the generated META-INF/maven/plugin.xml, <packaging>maven-plugin</packaging> POM, process-classes execution, and <pluginManagement> compiler encoding inheritance work end-to-end.

Leaving a COMMENT review for one breaking bug and a few concerns to address before approval:

  • Breaking: Utf8Sources.copy does not normalize paths (., ..), which breaks the target/ / utf8-sources/ skip guard and causes self-copying with mojibake corruption.
  • Concerns: release sequencing while PostHog/posthog#144749 and PostHog/posthog-android#1019 are still open drafts; missing automated META-INF/maven/plugin.xml / Maven packaging test; contradictory multi-module sourceRoots guidance in posthog-maven-plugin/README.md; Windows JDK 8–17 unset encoding skipping UTF-8 transcoding; and asymmetric behavior for missing explicit <sourceRoots> with requireUpload=true vs empty existing src/main/java once credentials are set.
  • Follow-up (outside this repo): once posthog-cli, posthog-server, and posthog-maven-plugin release, add JVM Maven source-upload documentation in PostHog/posthog.com (contents/docs/error-tracking/upload-source-maps/ and contents/docs/libraries/java/index.mdx), and optionally add posthog-maven-plugin to RELEASING.md and root CHANGELOG.md.

AI-assisted review.

Comment thread posthog-maven-plugin/build.gradle.kts Resolved
Comment thread posthog-maven-plugin/README.md Resolved
Comment thread posthog-maven-plugin/build.gradle.kts Resolved
@dustinbyrne
dustinbyrne requested a review from a team November 30, 2026 19:52
…load

A failed upload failed the build even without requireUpload, so a
PostHog outage, a revoked key or rate limiting broke deploys. It now
warns and ships no id. Local builds uploaded too, so a developer who
ran posthog-cli login uploaded work in progress on every mvn test or
mvn install, and could not build offline.

Without requireUpload, the goal now uploads only from a CI build, not
offline, and not in a module that another module of the build depends
on, whose posthog-meta.properties could replace the application's on
the classpath. requireUpload uploads from every build and fails it when
the upload can't run, for deploy builds such as a Dockerfile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJADQzM8ma8T9RauvMg5
- Normalize source roots, so ${project.basedir}/. no longer makes the
  UTF-8 copy walk into the build directory and copy itself.
- Add additionalSourceRoots, which adds to the default roots, for the
  other modules of a multi-module build. sourceRoots still replaces
  them.
- A configured source root that does not exist warns, and fails a
  required upload.
- An unset source encoding falls back to the platform charset, which
  javac also uses, so windows-1252 sources on Java 17 get UTF-8 copies.
- The help probe calls the CLI too old only when clap rejects the
  command, and otherwise reports the exit code and first output line.
- Resolve a relative cliExecutable against the project, report a
  configured path that does not exist, look for the CLI in nvm, strip
  quotes from Windows PATH entries, and refuse a cmd line that would
  cut a path with spaces short.
- Compile with --release 8, and test the generated plugin.xml in the
  jar.
- Test the session checks through two hooks instead of the deprecated
  MavenSession constructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkuJADQzM8ma8T9RauvMg5
@ablaszkiewicz
ablaszkiewicz marked this pull request as draft December 1, 2026 11:57
@ablaszkiewicz

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. Every inline point is addressed in f82d858, with a reply on each thread. The PR is back in draft until posthog-cli ships jvm upload (PostHog/posthog#144749) and #1019 is ready to release with it. The posthog.com docs follow once all three are released.

rafaeelaudibert and others added 2 commits December 2, 2026 13:03
The upload-sources goal now runs `hog error-tracking process --kind jvm`
instead of `posthog-cli jvm upload`, since only hog has the command.

- Find hog the way the Android Gradle plugin does: PATH, then
  ~/.local/bin, nvm, /usr/local/bin and /opt/homebrew/bin, then the
  project's node_modules/.bin when node is installed. On Windows, search
  PATH with PATHEXT as cmd does, then ~/.local/bin/hog.exe, and run the
  hog.exe of the npm platform package instead of the hog.cmd shim.
- Pass the dotenv file as HOG_DOTENV_FILE.
- A missing hog skips with the install commands. Exit 3 skips as missing
  credentials, and exit 2, which an older hog returns for --kind jvm and
  --meta-out, skips with a `hog upgrade` hint. Every failure fails the
  build only when requireUpload is set.
- Drop the plugin's deletes of posthog-meta.properties after a failed
  run, which hog guarantees. Keep the delete for builds that never start
  hog, and keep the UTF-8 copies, because hog skips non-UTF-8 files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaeelaudibert rafaeelaudibert changed the title feat(maven-plugin): add posthog-maven-plugin to upload jvm sources feat(maven-plugin): add posthog-maven-plugin to upload jvm sources with hog Dec 2, 2026
rafaeelaudibert and others added 6 commits December 2, 2026 13:17
Rename PostHogCli to Hog, the cliExecutable parameter to hogExecutable
(property posthog.hogExecutable), and the tests and helpers that named
the CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Call the tool hog without code formatting, keep code formatting for the
`hog error-tracking process` command and `posthog.hogExecutable`, and
list credentials as a requirement instead of only a personal API key,
since hog also logs in with a CI job's OIDC token or `hog auth login`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- One blank-string helper, Hog.isBlank, instead of four copies.
- One environment key lookup behind pathKey and variable.
- One cmd rejection message, and firstUnsafeForCmd takes the executable
  and its arguments.
- Both hog exit codes in Hog, one branch for every non-zero exit with
  the `hog upgrade` hint only for exit 2, and a shorter credentials
  message.
- skipOrFail(String), metaPropertiesFile() and home() helpers, and hog
  resolved from the mojo's environment field.
- Look node up once for a project launcher.
- Decode with new String, which already replaces unmappable bytes, and
  create the target folder once per copied file.
- Tests: an assertThrows helper for required uploads, one helper that
  writes executable scripts, the meta file name from the constant, and
  no duplicate success test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run `hog --version` before the upload. posthog-cli, or a hog older than
MIN_HOG_VERSION (1.1.0, the first release with `hog error-tracking
bundle`), skips the upload with a warning that says how to install or
update hog, and fails it with requireUpload. The upload never runs with
either. Versions compare numerically and ignore a prerelease suffix, and
output without a version counts as too old. The exit 2 hint stays as a
fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UTF-8 copies keep only Java and Kotlin files, so hog can't see the
build files that mark a build output folder inside a copy. A broad root
with a non-UTF-8 encoding could then upload generated sources that the
same build without the copy skips. The copy now applies hog's folder
skips to the original tree: hidden folders, node_modules, test source
sets under src, and build, target and out folders next to a build file
or src. A root is always copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A module counted as a library whenever another module of the build
depended on it, so an application with an integration test, coverage or
distribution module skipped the upload in CI with only an info line. Only
a dependent module that runs the goal on sources of its own makes a module
a library now.

- A failed UTF-8 copy warns instead of failing a build whose upload is
  optional.
- The UTF-8 copies keep a Java file that is valid UTF-8 already, so the
  sources of a module with another encoding stay readable.
- The version check finds the version below a launcher warning on stderr.
- The README says how a dotenv path resolves in a multi-module build, how
  a generated timestamp defeats reuse, and that hog now keeps a file that
  isn't UTF-8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review December 3, 2026 20:02
throws IOException {
String name = file.getFileName().toString();
boolean java = name.endsWith(".java");
if (!java && !name.endsWith(".kt")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: UTF-8 staging follows source symlinks

When a non-UTF-8 encoding enables staging, walkFileTree passes symlinks to this visitor and readAllBytes/Files.copy dereference them, so a .java or .kt link to an unrelated local file becomes a regular staged file submitted for upload. Reject non-regular entries using the supplied no-follow attributes before reading or copying to prevent credentials or other files outside the source tree from being included.

Suggested change
if (!java && !name.endsWith(".kt")) {
if (!attributes.isRegularFile() || (!java && !name.endsWith(".kt"))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking: Confirming this as a blocking issue before approval, with two additional impacts beyond copying an external file:

  1. Bypasses hog's explicit symlink defenses: hog intentionally skips symlinks during discovery (PostHog/posthog hog/src/error-tracking/discover.ts:133-161, Dirent.isFile()) and refuses them with lstat + O_NOFOLLOW in hog-worker (hog/worker/src/sources.rs:394-427). Materializing a .java/.kt symlink as a regular file inside target/posthog/utf8-sources/ defeats both guards.
  2. Broken symlinks abort the entire upload: A dangling .java/.kt symlink throws NoSuchFileException at line 98/100 and aborts Utf8Sources.copy (failing the build when requireUpload=true), whereas hog skips symlinks cleanly.

Executed verification (head 211887ec, JDK 17.0.16, Gradle 9.9.2, macOS arm64):

  • Valid .java/.kt symlinks to ../secret.env were materialized as regular files in target/posthog/utf8-sources/0/com/acme/Leak.java (finding2a_utf8CopiesSkipSymlinks failed; positive control App.java passed).
  • A broken Broken.java symlink threw java.nio.file.NoSuchFileException at Utf8Sources.java:98 (finding2b_utf8CopiesDoNotCrashOnBrokenSymlink failed).
@Test
public void utf8CopiesSkipSymlinksAndBrokenSymlinks() throws Exception {
    assumeUnix();
    File secret = new File(temp.getRoot(), "secret.env");
    Files.write(secret.toPath(), "SECRET_TOKEN=top-secret\n".getBytes(StandardCharsets.UTF_8));
    File javaDir = sourceRoot("src/main/java/com/acme");
    Files.write(
            new File(javaDir, "App.java").toPath(),
            "package com.acme;\n// caf\u00e9\nclass App {}\n".getBytes(StandardCharsets.ISO_8859_1));
    Files.createSymbolicLink(new File(javaDir, "Leak.java").toPath(), secret.toPath());
    Files.createSymbolicLink(new File(javaDir, "Leak.kt").toPath(), secret.toPath());
    Files.createSymbolicLink(
            new File(javaDir, "Broken.java").toPath(),
            new File(temp.getRoot(), "missing-target.java").toPath());

    File copy =
            Utf8Sources.copy(
                            Collections.singletonList(new File(basedir, "src/main/java")),
                            StandardCharsets.ISO_8859_1,
                            new File(basedir, "target/posthog/utf8-sources"),
                            new File(basedir, "target"))
                    .get(0);

    assertTrue(new File(copy, "com/acme/App.java").isFile());
    assertFalse(new File(copy, "com/acme/Leak.java").exists());
    assertFalse(new File(copy, "com/acme/Leak.kt").exists());
    assertFalse(new File(copy, "com/acme/Broken.java").exists());
}

Consider applying the !attributes.isRegularFile() guard above and adding the regression test covering both valid and broken symlinks.

AI-assisted review.

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing every item from the earlier review and migrating cleanly to hog 1.1.0 — the 44 unit tests (including the META-INF/maven/plugin.xml jar descriptor test) and generated <packaging>maven-plugin</packaging> POM look great.

Leaving a COMMENT review for two breaking issues and two concerns before approval:

  • Breaking: On Windows, versionProblem() spawns cmd /c <executable> --version before Hog.firstUnsafeForCmd() runs (UploadSourcesMojo.java:177 inline).
  • Breaking: Utf8Sources.copy dereferences .java/.kt symlinks into regular staged files (bypassing hog's O_NOFOLLOW symlink boundary) and crashes on broken symlinks — replied directly on open thread #1011 (comment) (Utf8Sources.java:91).
  • Concern: uploadsOwnSources() ignores <skip>true</skip>, <posthog.skip>true</posthog.skip>, and <phase>none</phase> on downstream modules (UploadSourcesMojo.java:283 inline).
  • Concern (release sequencing — referencing resolved thread #7): hog/v1.1.0 is now released, but companion posthog-server PR #1019 (8633d1b8) is still an open draft and posthog-maven-plugin/README.md:12 still leaves the minimum posthog-server version unpinned. Because .github/workflows/release.yml versions and publishes all pending .changeset/*.md files together, consider holding merge (or keeping #1011 in draft) until #1019 is ready to ship before/with it and pinning the concrete posthog-server minimum version in posthog-maven-plugin/README.md:12.
  • Suggestions: Two small parity cleanups with hog / #1012 inline (Utf8Sources.java:40 *Test suffix rule and UploadSourcesMojo.java:234 exit-2/exit-3 hints).
  • Follow-up (post-release, outside this PR): Publish JVM Maven source-upload documentation in PostHog/posthog.com once #1019 and #1011 release (and optionally add posthog-maven-plugin to RELEASING.md).

AI-assisted review.


String versionProblem;
try {
versionProblem = versionProblem(executable, isWindows, installHint);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking: On Windows, versionProblem() invokes cmd /c <executable> --version before Hog.firstUnsafeForCmd() runs at lines 194–211, bypassing the cmd safety check for executable.

Trigger → actual → expected: When executable does not end with .exe (for example a PATH-resolved or configured hog.cmd shim under a path like C:\Users\R&D\...\hog.cmd, or a bare posthog.hogExecutable containing & such as hog&whoami), line 177 calls versionProblem() → start() → Hog.commandLine(), spawning cmd /c <executable> --version before lines 194–211 ever execute. Expected: Hog.firstUnsafeForCmd / Hog.cmdSplitsPath runs before any cmd /c invocation (including --version), matching companion PR #1012 (PostHogCliExecTask.kt:191-203).

Executed verification (head 211887ec, JDK 17.0.16, Gradle 9.9.2, macOS arm64; control_normalUploadPasses passed): Setting os.name=Windows 11 and mojo.hogExecutable = "hog&whoami" logged [debug] Running cmd /c hog&whoami --version and failed with Could not run hog (hog&whoami)... instead of "would not pass this value unchanged: hog&whoami". An existing .../R&D/hog.cmd passes isInstalledAt() (line 163) and hits the same versionProblem() → cmd /c path before line 194.

@Test
public void cmdUnsafeExecutableIsRejectedBeforeVersionProbe() throws Exception {
    mojo.project.addCompileSourceRoot(sourceRoot("src/main/java").getAbsolutePath());
    File unsafeShim = executable(new File(temp.newFolder("R&D"), "hog.cmd"), "@echo 1.1.0\r\n");
    String previousOs = System.getProperty("os.name");
    System.setProperty("os.name", "Windows 11");
    try {
        for (String candidate : Arrays.asList("hog&whoami", unsafeShim.getAbsolutePath())) {
            mojo.hogExecutable = candidate;
            String message = requiredUploadFailure().getMessage();
            assertTrue(message, message.contains("would not pass this value unchanged: " + candidate));
        }
    } finally {
        if (previousOs == null) {
            System.clearProperty("os.name");
        } else {
            System.setProperty("os.name", previousOs);
        }
    }
}

Consider moving the Hog.runsThroughCmd / firstUnsafeForCmd / cmdSplitsPath check ahead of versionProblem() (or into a helper called before every start()), optionally also rejecting executable values containing both spaces and cmd unquote characters &<>()@^| (matching #1012 Utils.kt:445-448), and adding the regression test above.

return false;
}
boolean runsGoal = false;
for (PluginExecution execution : plugin.getExecutions()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern: uploadsOwnSources() treats any downstream module that declares an upload-sources execution as uploading, even when that module explicitly disables the goal with <skip>true</skip>, <posthog.skip>true</posthog.skip>, or <phase>none</phase>.

Trigger → actual → expected: When posthog-maven-plugin is configured in a shared parent POM and a downstream module (such as an integration-test or JMH module with helper classes under src/main/java) disables the plugin using <skip>true</skip>, <properties><posthog.skip>true</posthog.skip></properties>, or <phase>none</phase>, uploadsOwnSources() still returns true. The application module then skips its upload in CI while the downstream module also skips, so neither module uploads and the application ships without posthog-meta.properties. Expected: a downstream module whose upload-sources execution is skipped or bound to phase=none does not suppress the application's upload.

Executed verification (head 211887ec, JDK 17.0.16, Gradle 9.9.2): With downstream modules configured with <skip>true</skip>, <phase>none</phase>, and posthog.skip=true, mojo.execute() logged Skipping the PostHog source upload: demo-it-skip depends on this module and uploads its own sources... and wrote no posthog-meta.properties.

@Test
public void uploadsWhenDependentModulesSkipOrDisableTheGoal() throws Exception {
    assumeUnix();
    mojo.project.addCompileSourceRoot(sourceRoot("src/main/java").getAbsolutePath());
    mojo.hogExecutable = fakeHog(0, true).getAbsolutePath();

    MavenProject skippedByConfig = dependentModule("demo-it-skip", true);
    Xpp3Dom config = new Xpp3Dom("configuration");
    Xpp3Dom skip = new Xpp3Dom("skip");
    skip.setValue("true");
    config.addChild(skip);
    skippedByConfig.getPlugin("com.posthog:posthog-maven-plugin").setConfiguration(config);

    MavenProject disabledByPhase = dependentModule("demo-it-phase-none", true);
    disabledByPhase.getPlugin("com.posthog:posthog-maven-plugin").getExecutions().get(0).setPhase("none");

    MavenProject skippedByProperty = dependentModule("demo-it-prop", true);
    skippedByProperty.getProperties().setProperty("posthog.skip", "true");

    mojo.dependents = Arrays.asList(skippedByConfig, disabledByPhase, skippedByProperty);
    mojo.execute();

    assertTrue(metaProperties().isFile());
}

Consider filtering executions in uploadsOwnSources() to ignore "none".equalsIgnoreCase(execution.getPhase()) and effective skip=true (checking execution config <skip>, then plugin config <skip>, then module.getProperties().getProperty("posthog.skip")), with a regression test covering all three opt-outs.

"settings.gradle.kts",
"build.sbt",
"build.xml");
private static final List<String> TEST_SOURCE_SETS =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider matching hog's *Test suffix rule instead of hardcoding four test source-set names, which both simplifies this code and keeps parity with hog and #1012.

In PostHog/posthog (hog/src/error-tracking/jvm.ts:39-41) and companion PR #1012 (Utf8Sources.kt:73), any directory under src matching name == "test" || name == "testFixtures" || name.endsWith("Test") is skipped. With the 4-entry list here, a non-UTF-8 project whose <sourceRoots> points to src and contains e.g. src/jvmTest or src/functionalTest stages it into utf8-sources/0/jvmTest (losing the src/ parent so hog then uploads it — verified by a JUnit test on 211887ec where Utf8Sources.copy([basedir/src], ISO_8859_1, ...) copied src/jvmTest/java/com/acme/AppTest.java).

Replacing TEST_SOURCE_SETS with name.equals("test") || name.equals("testFixtures") || name.endsWith("Test") covers androidTest, integrationTest, and all custom *Test source sets in one expression.

return;
}
if (exitCode != 0) {
// A hog from before JVM source uploads rejects --kind jvm and --meta-out as a usage

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider aligning the exit-code 2 and exit-code 3 hints here (lines 227–238) with hog >= 1.1.0 and companion PR #1012 (PostHogUploadJvmSourcesTask.kt:205-217).

Because versionProblem() (line 177) has already verified hog >= 1.1.0, an exit code 2 (EXIT_USAGE) is no longer from an outdated hog — it typically comes from an invalid setting like HOG_RELEASE_MODE or HOG_UPLOAD_CONCURRENCY (hog/src/commands/error-tracking/shared.ts:144-174), so pointing users to hog upgrade can mislead them. Similarly, exit code 3 (EXIT_NEEDS_PERSON, hog/src/core/errors.ts:51-65) also covers expired sessions, OIDC CI setup (hog ci setup), and missing scopes in addition to missing credentials.

Matching #1012's wording (pointing exit 2 at hog's output above and mentioning hog ci setup / re-login on exit 3) makes both failure paths clearer.

@dustinbyrne
dustinbyrne requested a review from a team December 3, 2026 21:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants